//
//  ViewController.m
//  控制器的view的显示
//
//  Created by J on 15/11/23.
//  Copyright © 2015年 J. All rights reserved.
//

#import "ViewController.h"
#import "TestViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
@interface ViewController ()
@property(nonatomic,strong)TestViewController  * VC;
@property(nonatomic,strong)OneViewController  * one;
@property(nonatomic,strong)TwoViewController  * two;
@property(nonatomic,strong)ThreeViewController  * three;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    TestViewController  * vc= [[TestViewController alloc]init];
    self.VC = vc ;
    vc.view.frame =CGRectMake(100, 100, 200, 300);
    vc.view.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:vc.view];
    
    //如果发现控制器的view还在 但是view上面的数据不显示  极大可能是因为 控制器被提前释放了
    //1.一个控制器的view是可以随意调整尺寸和位置的
    //2.一个控制器的view是可以随意添加到其他view中
    //3.如果将一个控制器的view 添加到其它view中显示 那么要想办法保证控制器不被销毁
    //4.原则: 只要view在 view所在的控制器必须要在 这样才能保证view内部的数据和业务逻辑(事件处理)正常

}

- (OneViewController *)one{
    
    if (!_one) {
        self.one =[[OneViewController alloc]init];
        self.one.view.frame = CGRectMake(10, 79, 300, 300);
        
    }
    return _one;
    
}

- (TwoViewController *)two{
    
    if (!_two) {
        self.two =[[TwoViewController alloc]init];
        self.two.view.frame = CGRectMake(10, 79, 300, 300);
        
    }
    return _two;
    
}


- (ThreeViewController *)three{
    
    if (!_three) {
        self.three =[[ThreeViewController alloc]init];
        self.three.view.frame = CGRectMake(10, 79, 300, 300);
        
    }
    return _three;
    
}


- (IBAction)vc1:(id)sender {
    
    [self.two.view removeFromSuperview];
    [self.three.view removeFromSuperview];
    [self.view addSubview:self.one.view];//一个控件不论调用多少次add都只会 add一次 图层里面也只会显示一层
    
    for (int i=0; i<100; i++) {
        [self.view addSubview:self.one.view];
        [self.view addSubview:self.one.view];
        [self.view addSubview:self.one.view];

    }
   


}

- (IBAction)vc2:(id)sender {
    
    [self.one.view removeFromSuperview];
    [self.three.view removeFromSuperview];
    [self.view addSubview:self.two.view];

}


- (IBAction)vc3:(id)sender {
    
    
    [self.one.view removeFromSuperview];
    [self.two.view removeFromSuperview];
    [self.view addSubview:self.three.view];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
